sysroot: Rework how we find booted deployment
authorColin Walters <walters@verbum.org>
Mon, 12 Mar 2018 18:55:51 +0000 (13:55 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 15 Mar 2018 17:43:19 +0000 (17:43 +0000)
commit5b3f79d4bb7dc80f4bc750a9e8911709646a5523
tree363c8ea98cd9ac7fecc1996d4de59f8103200dd4
parentbb9cc8912a0208a1b383ddbd24ecde6c7453e730
sysroot: Rework how we find booted deployment

I was looking at this code in prep for "staging" deployments,
and there are several cleanups to be made here.  The first
thing I noticed is that we look for the `ostree=` kernel argument,
but the presence of that should be exactly equivalent to having
`/run/ostree-booted` exist.  We just added a member variable for
that, so let's make use of it.

Related to this, we were erroring out if we had the karg but
didn't find a deployment.  But this can happen if e.g. one is
using `ostree admin --sysroot` from an ostree-booted system!  It's
actually a bit surprising no one has reported this so far; I guess
in the end people are either using non-ostree systems or running
from containers.

Let's add a member variable `root_is_sysroot` that we can use
to determine if we're looking at `/`.  Then, our more precise
"should find a booted deployment" state is when both `ostree_booted`
and `root_is_sysroot` are TRUE.

Next, rather than walking all of the deployments after parsing,
we can inline the `fstatat()` while parsing.  The mild ugly
thing about this is assigning to the sysroot member variable while
parsing, but I will likely clean that up later, just wanted to avoid
rewriting everything in one go.

Closes: #1497
Approved by: jlebon
src/libostree/ostree-sysroot-private.h
src/libostree/ostree-sysroot.c